In the last video, we created a UI for our battle royale.
Let's go ahead and take a look at it.
Starter GUI.
That screen gooey and then go to Battle Royale frame.
We're going to make that visible.
Check that we also need to make it so that if you hit the accept button, you're added to the queue
that will be teleported.
If you hit the decline, you're not added to the queue.
If you accept and then change your mind and decline, you're going to be taken out of the queue.
I thought that would be a good way of doing it.
Let's bring up our battle royale.
Look in our battle royale, look, let's add two variables for our accept and decline buttons.
So I'll go down to the bottom of the declaration section, do a local accept button.
We'll do a battle frame, dot accept button and do the same thing for your decline.
So we have a decline button.
Battle frame dot decline button.
Nice.
Now let's get that button.
We're going to go down to the bottom of the script.
We'll get our accept button dot activated colon connect function so nothing gets passed into that function.
Let's make the button that we press have the have a thicker border so we know what is selected.
So I'll say accept button on the buttons.
We have this border size pixel, maybe make it like 5 or 6.
Let's try five.
And then don't forget we have our decline button.
So let's make sure that border size pixel is small.
We'll make it one, then we'll use our battle re the same remote event that opened up our our UI.
We're going to send back a colon.
We'll do a fire server.
A true.
So if we hit the accept, we're going to send back a true.
We're going to do almost exactly the same for the decline.
I just did a copy there.
Paste and be very careful when you copy and paste.
We're going to do a decline button.
The accept button is going to have a thin pixel border and the decline is going to be thick to show
which one you selected.
Now here, do not miss this.
It's going to be hard to troubleshoot because you won't get an error.
You just get two, two accepts.
So on your decline, make sure you have a false here.
Now on the server side, we're not handling the events coming over from the client, but we're going
to do that in a minute.
Let's test to see what our buttons look like.
There we go.
And we should make this a little smaller, too.
And we also need to remember to turn visible off and hit the tab button.
There we go.
That's the.
Except I could see that pretty good.
That's the decline.
That's looking good.
I think we're done with that script.
Let's go ahead and turn this off.
So in our battle royale, look, we have these two events here where we fire to the server.
Our battle is firing to the server, either a true or false, depending on whether we should add them
to the queue, not add them or remove them if they're in the queue.
Let's go up to our workspace.
Battle will initiate battle script.
All right.
Now we already have our battle ready.
That's what brought up the UI and made the noise and everything else, the little sound.
Let's go to the bottom of that script.
We're going to add an event handler for client side events.
I'll just do Battle Re dot on server event Connect it.
I'm going to call this function.
I haven't created it yet, so it'll be an error.
But player response.
All right.
So there's an error because we haven't defined it.
I'm going to copy it so I spell it right.
Control C I'm going to move up a little bit, maybe above send players.
Yeah, maybe I'll make this the top function.
Let's say local function control V player response.
And we're going to get a player because it came from a client event.
So whoever pressed the button player comes automatically.
We didn't have to send it and then we're going to get our response.
That's a true or a false player response is going to add the player to the queue based on what the response
is.
We're going to need two helper functions, though, before we proceed.
I'll do a local function and I'm going to check to see if the player is already in the queue.
We don't want to have them in the queue More than once, I'm going to say has let me move my mouse player
and this is going to check to see if the table I'll just call it tab has the player or I should just
call that L for element if the element is a value in the table.
All right.
I'm going to do a for loop in here for I and V in pairs.
We'll check for, we'll check all the elements in the table and do if V which is going to be a player
in this case equals equals the player that got passed in.
Then we're going to return a true right.
The player was in the table.
So this is going to be like one, two, three, four, five, and this is going to be the players.
So we really don't need to have an I.
We're not going to use the index.
Sometimes it's good to do that and underscore will show people who are reading your code Oh they're
not using the index variable.
They're only using the value.
Let's put a print statement in here too, so we could check our code.
I'm going to say print has player found player equals and now we'll just print out the player name.
If we get to the end of our table and we haven't returned a true, then we're going to know that player
was not in the table.
So we'll say return false.
And if you don't have the return false, you'll return nil and lua.
It treats nil as a false.
So if you miss this line, you're not going to have a problem.
I like to keep it there for completeness.
Now we're going to have another function to remove players from the queue if they accept and then change
their mind and decline.
Let's do a local function.
Remove player.
I'll have a tab.
That's the table that's going to be the player table or the player queue.
We call that and then player.
I'm not using global variables in here or script script global because I might want to move this to
a module or script.
So let's do a for we could do our I or we could do an underscore.
We're not going to use the index V in pairs.
We'll have our table again.
Do if V equals equals player, then table dot remove.
Pass in the table.
Oh, you know what?
We are going to need the eye because this one removes based on index.
Boo.
All right, so we need that eye.
So for inv in Paris, we're checking on the v, but we're doing the removal based on the eye, the index.
So maybe found them.
Found that player in the third spot, yank them out based on three.
Now we can go down to our player response and finish that.
So the event came in fired off player response.
We're going to get the player, we're going to get a response.
It's either true or false.
I'll do a IF player just to make sure the player is there and response.
So they hit true, right?
They hit the accept button.
Let me move that up a little bit.
If not, has player in our player queue put in the player, then table dot insert player queue and player
and we'll put a print statement here too just to make sure we know what's happening.
So player has joined.
Did I spell join?
Right.
Yeah.
Joined the queue and let's put the player name.
So we'll say oh we can put the whole queue.
Yeah.
Let's do the old cute.
Just so we see what's going on.
We don't want to accidentally, like, miss players being removed or something.
All right.
So if the response was false, let's go to this end right here.
And we're going to do an else.
Right.
So we can do an else.
If I think an else is safe, though.
We'll say remove player.
We'll get our player queue.
Take a look at the player and the player queue.
And then just print player has been removed from the queue.
And maybe we'll print the whole player queue.
Now let's put the player in this one.
If we're testing this on Roblox server, we may not be able to see the whole queue unless we mess around
with the settings pretty severely.
Let's scroll down to start registration.
What do we have to change?
Well, this is good.
We play our sound.
We're not going to worry about inserting players into the table.
We have functions for that fire, all clients that's going to bring up their UI.
We're going to wait this approximately the same amount of time.
We're not really going to be able to see a difference.
That's about 15 seconds.
Let's go ahead.
Whoops and send players.
And then we'll say is initiated is false, we'll be able to reset the queue.
Let's take a look at send players.
Let's go on up here.
Send players right here.
All right.
So when we go ahead and send players, let's make sure there's a sufficient number of players in the
queue.
I'm going to make the required players one.
So I'll say if that's the number of players in the player queue is greater than or equal to, we're
going to need a variable for required players.
We don't have that yet.
So it's going to give us an error.
So if that happens.
Let's go down here and finish our F.
Its format.
Our document.
Let's grab this name.
Go up to the top where we do our variable declaration.
Perhaps after the sound we'll do a local required players.
I'm just going to make it one.
But you can make it three.
You can make it five.
Remember, we're going to have awards, but maybe if one player goes, they deserve the reward.
Even if even if they're not fighting anybody, they they participated.
All right.
We'll go back down to the send players.
We're checking our required players.
I think I'll put a little print statement in here because we're going to we're going to have to check
we're going to have to do some troubleshooting.
I'm sure it's going to work out.
But just in case, we'll say prepare to teleport and you can do a UI for that if you want.
All right.
We're going to get our code.
We're going to teleport and we got our player queue.
I think we're ready to test.
Let's go ahead and save this off now.
We're not going to have our weapons transferred over.
We haven't done that yet.
And we're not going to be able to get back even when we die.
But let's go over to our website, check out our game to see if we can teleport to the other side.
I'm at the Roblox website, logged in as Simtek Nitro one and I see my game right here.
Let's go ahead and start that up.
And I'm also going to get my alt in the game too.
So I clicked on it.
I'll hit the play.
We're going to download our player.
All right.
20 minutes later, after all of my updates.
Let's go ahead and hit this little cog up here in the corner to bring up our developer console.
Where is it?
Settings Developer console.
Take a look at what's going on.
I'll move that up here.
Hit server side.
We're getting some health notifications.
This is my alt right here.
I have the phone so that he could accept the battle.
Let's bring up our battle.
This is going to be in a way, isn't it?
Let's bring it down here.
Hit the battle.
Ding.
I'm going to accept.
I'm going to get my alt.
He's going to accept.
And.
Oh, yeah, look, the player has joined the queue.
We have to change our settings in order to actually see the whole table.
That's all right.
We got two notifications.
Let's see if we teleport.
Look at that.
We're both in the world.
So we teleported a group to our private server.
Now, if somebody or even me, if I was to join the leave and join the game and come back, I could
not get to this because this is a private server.
You need the code, a reserved server.
So that's pretty cool.
Now all we have to do is create the logic on this end to send the people back when they die.
Last person standing gets the reward.
We're going to set up.
Set up a little banner.
Yay!
You win.
Maybe give him a prize.
We also have to.
Figure out how to bring our weapons, right?
We have no weapons and we don't have any punching or anything either, so we can't even bruise them
to death.
That's pretty cool, though.
I will see you in the next video.
We will continue on our battle royale.